package com.practice.Stream流使用;

import org.apache.commons.lang3.StringUtils;

import java.util.stream.Stream;
/**
 * Created by IntelliJ IDEA2022.3.2
 * @Author: Tenghw
 * @Date: 2023/03/03  15:24
 * @Description: stream流中limit和skip比较
 */
public class Demo2 {
    public static void main0(String[] args) {
        // 1：当操作有限流时
        Stream<Integer> stream1 = Stream.of(1, 2, 4, 5, 6, 9);
        Stream<Integer> limit = stream1.limit(3);
        limit.forEach(System.out::println);
        System.out.println("---------------");
        Stream<Integer> stream2 = Stream.of(1, 2, 4, 5, 6, 9);
        Stream<Integer> skip = stream2.skip(3);
        skip.forEach(System.out::println);
    }

    public static void main(String[] args) {
        // 2：当操作无限流时
        Stream<Integer> stream1 = Stream.iterate(1, x -> x + 2);
        Stream<Integer> limit = stream1.limit(3);
        limit.forEach(System.out::println);
        System.out.println("---------------");
        Stream<Integer> stream2 = Stream.iterate(1, x -> x + 2);
        Stream<Integer> skip = stream2.skip(3);
        skip.forEach(System.out::println);
    }


}
